package com.wk.data.cahce;

import java.util.LinkedHashMap;
// 基于LinkedHashMap实现lru
public class LruLinkedHashMap extends LinkedHashMap<String, Object>{

	private int capcity;
	public LruLinkedHashMap(int cap) {
		super(16, 0.75f, true); //accessOrder true 访问顺序
		this.capcity = cap;
	}
	@Override
	protected boolean removeEldestEntry(java.util.Map.Entry<String, Object> eldest) {
		return size()>capcity;
	}
	public static void main(String[] args) {
		LruLinkedHashMap lru = new LruLinkedHashMap(3);
		lru.put("a", 1);
		lru.put("b", 2);
		lru.put("c", 3);
		lru.put("d", 4);
		System.out.println(lru.get("b"));
		System.out.println(lru);
	}

}
